package trees;

import java.util.HashMap;
import java.util.List;

public class TreePrinter {
	
	HashMap<Integer, String> dictionary;
	
	public TreePrinter(HashMap<Integer, String> dictionary){
		this.dictionary = dictionary;
	}

	public void printTree(AttributeNode node){
		System.out.println("\tbegin tree: ");
		printTreeRecursively(node, 2);
		System.out.println("\tend tree: ");
	}
	
	private void printTreeRecursively(AttributeNode node, int depth){
		int attribute = node.getAttribute();
		String indentString = getIndentString(depth);
		String printString = indentString + attribute + ":" + dictionary.get(attribute);
		printString += ":pos = " + node.getPositionWithinSiblings();
		System.out.println(printString);
		List<AttributeNode> children = node.getChildren();
		for(AttributeNode child : children)
			printTreeRecursively(child, depth +1);
		
	}	
	
	private static String getIndentString(int depth){
		StringBuffer result = new StringBuffer("");
		for(int i = 0; i < depth; i ++)
			result.append("\t");
		return result.toString();
	}
	
}
